/*
 * @Date: 2023-02-14 09:45:44
 * @LastEditTime: 2023-05-20 09:23:00

 * 介绍:
 */
import useClipboard from "vue-clipboard3";
import { toast } from "@@/hooks/vantHooks";
import { i18n } from "@@/language/index";

/**
 * 复制文本
 * @param text 复制的内容
 * @returns 成功失败
 */
export async function copyText(text: string): Promise<boolean> {
  const { toClipboard } = useClipboard();
  //@ts-ignore
  const { t } = i18n.global;
  try {
    await toClipboard(text);
    toast.success(t("fu-zhi-cheng-gong"));
    return true;
  } catch (e) {
    toast.error(t("fu-zhi-shi-bai"));
    return false;
  }
}

export function isEthAddress(address: any): address is string {
  return /^0x[A-Za-z0-9]{40}$/.test(address);
}
